package com.xyzh05.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

import com.xyzh05.util.DateUtil;

@Entity
@Table(name="user_info")
@Searchable
@XmlRootElement
public class UserInfo extends BaseObject implements Serializable {
	private static final long serialVersionUID = 5492989709183149588L;
	
	public static final Short CALENDAR_LUNAR = 1;
	public static final Short CALENDAR_GREGORIAN = 2;
	
    private Long id;
    private User user;
    private Short birthType = CALENDAR_LUNAR;
    private String birthYear;
    private String birthMonth;
    private String birthDay;
    private String constellation;
    private Short blood;
    private Short sensation;
    private String code;
    private String address;
    private String communication;
    private String county;
    private String province;
    private String city;
    private String profession;
    private String position;
    private String deptName;
    private String deptAddress;
    private String avatar;
    private String phone;
    private Date updateTime = DateUtil.getNow();;
    private String nickName;
    private String contact;

    @Id @GeneratedValue(strategy=GenerationType.AUTO) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @OneToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="user_id")
    public User getUser() {
        return this.user;
    }
    
    public void setUser(User user) {
        this.user = user;
    }
    
	@Column(name="contact")
    @SearchableProperty
    public String getContact() {
		return contact;
	}

	public void setContact(String contact) {
		this.contact = contact;
	}

	@Column(name="birth_type")
    @SearchableProperty
    public Short getBirthType() {
        return this.birthType;
    }
    
    public void setBirthType(Short birthType) {
        this.birthType = birthType;
    }
    
    @Column(name="birth_year", length=16)
    @SearchableProperty
    public String getBirthYear() {
        return this.birthYear;
    }
    
    public void setBirthYear(String birthYear) {
        this.birthYear = birthYear;
    }
    
    @Column(name="birth_month", length=16)
    @SearchableProperty
    public String getBirthMonth() {
        return this.birthMonth;
    }
    
    public void setBirthMonth(String birthMonth) {
        this.birthMonth = birthMonth;
    }
    
    @Column(name="birth_day", length=16)
    @SearchableProperty
    public String getBirthDay() {
        return this.birthDay;
    }
    
    public void setBirthDay(String birthDay) {
        this.birthDay = birthDay;
    }
    
    @Column(name="constellation", length=8)
    @SearchableProperty
    public String getConstellation() {
        return this.constellation;
    }
    
    public void setConstellation(String constellation) {
        this.constellation = constellation;
    }
    
    @Column(name="blood")
    @SearchableProperty
    public Short getBlood() {
        return this.blood;
    }
    
    public void setBlood(Short blood) {
        this.blood = blood;
    }
    
    @Column(name="sensation")
    @SearchableProperty
    public Short getSensation() {
        return this.sensation;
    }
    
    public void setSensation(Short sensation) {
        this.sensation = sensation;
    }
    
    @Column(name="code", length=16)
    @SearchableProperty
    public String getCode() {
        return this.code;
    }
    
    public void setCode(String code) {
        this.code = code;
    }
    
    @Column(name="address", length=128)
    @SearchableProperty
    public String getAddress() {
        return this.address;
    }
    
    public void setAddress(String address) {
        this.address = address;
    }
    
    @Column(name="communication", length=32)
    @SearchableProperty
    public String getCommunication() {
        return this.communication;
    }
    
    public void setCommunication(String communication) {
        this.communication = communication;
    }
    
    @Column(name="county", length=16)
    @SearchableProperty
    public String getCounty() {
        return this.county;
    }
    
    public void setCounty(String county) {
        this.county = county;
    }
    
    @Column(name="province", length=16)
    @SearchableProperty
    public String getProvince() {
        return this.province;
    }
    
    public void setProvince(String province) {
        this.province = province;
    }
    
    @Column(name="city", length=16)
    @SearchableProperty
    public String getCity() {
        return this.city;
    }
    
    public void setCity(String city) {
        this.city = city;
    }
    
    @Column(name="profession", length=32)
    @SearchableProperty
    public String getProfession() {
        return this.profession;
    }
    
    public void setProfession(String profession) {
        this.profession = profession;
    }
    
    @Column(name="position", length=16)
    @SearchableProperty
    public String getPosition() {
        return this.position;
    }
    
    public void setPosition(String position) {
        this.position = position;
    }
    
    @Column(name="dept_name", length=32)
    @SearchableProperty
    public String getDeptName() {
        return this.deptName;
    }
    
    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }
    
    @Column(name="dept_address", length=128)
    @SearchableProperty
    public String getDeptAddress() {
        return this.deptAddress;
    }
    
    public void setDeptAddress(String deptAddress) {
        this.deptAddress = deptAddress;
    }
    
    @Column(name="avatar", length=128)
    @SearchableProperty
    public String getAvatar() {
        return this.avatar;
    }
    
    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }
    
    @Column(name="phone", length=16)
    @SearchableProperty
    public String getPhone() {
        return this.phone;
    }
    
    public void setPhone(String phone) {
        this.phone = phone;
    }
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="update_time", nullable=false, length=19)
    @SearchableProperty
    public Date getUpdateTime() {
        return this.updateTime;
    }
    
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    
    @Column(name="nick_name", length=16)
    @SearchableProperty
    public String getNickName() {
        return this.nickName;
    }
    
    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        UserInfo pojo = (UserInfo) o;

        if (user != null ? !user.equals(pojo.user) : pojo.user != null) return false;
        if (birthType != null ? !birthType.equals(pojo.birthType) : pojo.birthType != null) return false;
        if (birthYear != null ? !birthYear.equals(pojo.birthYear) : pojo.birthYear != null) return false;
        if (birthMonth != null ? !birthMonth.equals(pojo.birthMonth) : pojo.birthMonth != null) return false;
        if (birthDay != null ? !birthDay.equals(pojo.birthDay) : pojo.birthDay != null) return false;
        if (constellation != null ? !constellation.equals(pojo.constellation) : pojo.constellation != null) return false;
        if (blood != null ? !blood.equals(pojo.blood) : pojo.blood != null) return false;
        if (sensation != null ? !sensation.equals(pojo.sensation) : pojo.sensation != null) return false;
        if (code != null ? !code.equals(pojo.code) : pojo.code != null) return false;
        if (address != null ? !address.equals(pojo.address) : pojo.address != null) return false;
        if (communication != null ? !communication.equals(pojo.communication) : pojo.communication != null) return false;
        if (county != null ? !county.equals(pojo.county) : pojo.county != null) return false;
        if (province != null ? !province.equals(pojo.province) : pojo.province != null) return false;
        if (city != null ? !city.equals(pojo.city) : pojo.city != null) return false;
        if (profession != null ? !profession.equals(pojo.profession) : pojo.profession != null) return false;
        if (position != null ? !position.equals(pojo.position) : pojo.position != null) return false;
        if (deptName != null ? !deptName.equals(pojo.deptName) : pojo.deptName != null) return false;
        if (deptAddress != null ? !deptAddress.equals(pojo.deptAddress) : pojo.deptAddress != null) return false;
        if (avatar != null ? !avatar.equals(pojo.avatar) : pojo.avatar != null) return false;
        if (phone != null ? !phone.equals(pojo.phone) : pojo.phone != null) return false;
        if (updateTime != null ? !updateTime.equals(pojo.updateTime) : pojo.updateTime != null) return false;
        if (nickName != null ? !nickName.equals(pojo.nickName) : pojo.nickName != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (user != null ? user.hashCode() : 0);
        result = 31 * result + (birthType != null ? birthType.hashCode() : 0);
        result = 31 * result + (birthYear != null ? birthYear.hashCode() : 0);
        result = 31 * result + (birthMonth != null ? birthMonth.hashCode() : 0);
        result = 31 * result + (birthDay != null ? birthDay.hashCode() : 0);
        result = 31 * result + (constellation != null ? constellation.hashCode() : 0);
        result = 31 * result + (blood != null ? blood.hashCode() : 0);
        result = 31 * result + (sensation != null ? sensation.hashCode() : 0);
        result = 31 * result + (code != null ? code.hashCode() : 0);
        result = 31 * result + (address != null ? address.hashCode() : 0);
        result = 31 * result + (communication != null ? communication.hashCode() : 0);
        result = 31 * result + (county != null ? county.hashCode() : 0);
        result = 31 * result + (province != null ? province.hashCode() : 0);
        result = 31 * result + (city != null ? city.hashCode() : 0);
        result = 31 * result + (profession != null ? profession.hashCode() : 0);
        result = 31 * result + (position != null ? position.hashCode() : 0);
        result = 31 * result + (deptName != null ? deptName.hashCode() : 0);
        result = 31 * result + (deptAddress != null ? deptAddress.hashCode() : 0);
        result = 31 * result + (avatar != null ? avatar.hashCode() : 0);
        result = 31 * result + (phone != null ? phone.hashCode() : 0);
        result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0);
        result = 31 * result + (nickName != null ? nickName.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("user").append("='").append(getUser()).append("', ");
        sb.append("birthType").append("='").append(getBirthType()).append("', ");
        sb.append("birthYear").append("='").append(getBirthYear()).append("', ");
        sb.append("birthMonth").append("='").append(getBirthMonth()).append("', ");
        sb.append("birthDay").append("='").append(getBirthDay()).append("', ");
        sb.append("constellation").append("='").append(getConstellation()).append("', ");
        sb.append("blood").append("='").append(getBlood()).append("', ");
        sb.append("sensation").append("='").append(getSensation()).append("', ");
        sb.append("code").append("='").append(getCode()).append("', ");
        sb.append("address").append("='").append(getAddress()).append("', ");
        sb.append("communication").append("='").append(getCommunication()).append("', ");
        sb.append("county").append("='").append(getCounty()).append("', ");
        sb.append("province").append("='").append(getProvince()).append("', ");
        sb.append("city").append("='").append(getCity()).append("', ");
        sb.append("profession").append("='").append(getProfession()).append("', ");
        sb.append("position").append("='").append(getPosition()).append("', ");
        sb.append("deptName").append("='").append(getDeptName()).append("', ");
        sb.append("deptAddress").append("='").append(getDeptAddress()).append("', ");
        sb.append("avatar").append("='").append(getAvatar()).append("', ");
        sb.append("phone").append("='").append(getPhone()).append("', ");
        sb.append("updateTime").append("='").append(getUpdateTime()).append("', ");
        sb.append("nickName").append("='").append(getNickName()).append("'");
        sb.append("]");
      
        return sb.toString();
    }

}
